Lab 7

  1. Write a program that does the following: Ask the user to enter the price of their items. The user can enter as many items as they want until the user enters the integer 0. Print out the total of their checkout. If the sum is greater than $100, print out "That's expensive!"
  2. Sample run of program:
    Enter the price of an item: > 27 Enter the price of an item: > 80 Enter the price of an item: > 0 Your checkout total is $107. That's expensive!

  3. Write a program that prompts the user for a positive integer. Validate the input and do not accept a negative number. Use a while loop to find the sum of all odd digits of the number.
  4. Sample run of program:
    Enter a positive integer: > -237 Invalid input! Try again: > 237 The sum of the odd digits in the number is 10.

  5. Write a program that reads in a positive integer from the user. Validate the input and do not accept a negative number. If the number contains a 5 at any position, print "Number contains a 5." Otherwise print "Number does not contain a 5."
  6. Sample run of program:
    Enter a positive integer: -21 Bad input! Try again: 1576 Number contains a 5.

    Another sample run of program:
    Enter a positive integer: 172 Number does not contain a 5.
  7. Write a program that reads in a sequence of integer inputs between 1 and 100 (using a while loop) until the user enters 0. At that point the program prints the counts of even and odd integers the user entered.
  8. Sample run of program:
    Enter a number: > 23 Enter a number: > 15 Enter a number: > 12 Enter a number: > 34 Enter a number: > 9 Enter a number: > 0 Number of even integers: 2 Number of odd integers: 3
  9. Write a program that reads in a sequence of integer inputs between 1 and 1000 (using a while loop) until the user enters a 0. At that point the program prints out the count of single-digit integers, two-digit integers, and three-digit integers the user entered. (The count of single-digit integers should not include the 0 entered at the end.)
  10. Sample run of program:
    Enter a number: > 1 Enter a number: > 762 Enter a number: > 84 Enter a number: > 17 Enter a number: > 987 Enter a number: > 0 Number of single-digit integers: 1 Number of two-digit integers: 2 Number of three-digit integers: 2